import { req } from '@/util/request'
import type { Page, PageOprion, ResData } from '@/types/index'
import type { GroupTable } from '@/types'
import { deepCopy } from '@/util/token'

// 查询
export function getAllGroup(page: PageOprion, cdn: GroupTable = {}): ResData<Page<GroupTable>> {
  cdn = deepCopy(cdn)
  return req.post('/group/get', {
    num: page.num,
    size: page.size,
    cdn
  })
}

// 添加角色
export function addGroup(data: GroupTable): ResData<any> {
  return req.post('/group/add', data)
}

//修改角色
export function updateGroup(data: GroupTable): ResData<any> {
  data = deepCopy(data)
  return req.post('/group/update', data)
}

// 删除角色
export function delGroup(ids: number[]): ResData<any> {
  return req.post('/group/del', ids)
}

//获取角色拥有的接口权限
export function getGroupAuth(id: number, type: string): ResData<number[]> {
  return req.get('/group/auth/get', { params: { id, type } })
}

// 更新角色的接口权限
export function updateGroupAuth(id: number, type: string, data: string[] | number[]): ResData<any> {
  return req.post('/group/auth/update', data, { params: { id, type } })
}

//获取角色拥有的接口权限
export function getGroupUser(id: number): ResData<number[]> {
  return req.get('/group/user/get', { params: { id } })
}

// 更新角色的接口权限
export function updateGroupUser(id: number, data: number[]): ResData<any> {
  return req.post('/group/user/update', data, { params: { id } })
}
